﻿using System;
using System.Linq.Expressions;
using Domain.Core.Specification;
using Domain.MainModule.Entities;

namespace Domain.MainModule.Identities
{
    public class IdentityTypeNameSpecification : Specification<IdentityType>
    {
        #region public properties

        public string IdentityTypeName
        {
            get;
            set;
        }

        #endregion

        #region constructor

        public IdentityTypeNameSpecification(string identityTypeName)
        {
            this.IdentityTypeName = identityTypeName;
        }

        #endregion

        #region public methods

        public override Expression<Func<IdentityType, bool>> SatisfiedBy()
        {
            Specification<IdentityType> spec = new TrueSpecification<IdentityType>();
            if (!string.IsNullOrEmpty(this.IdentityTypeName) && !string.IsNullOrWhiteSpace(this.IdentityTypeName))
            {
                spec &= new DirectSpecification<IdentityType>(c => c.Name.ToLower() == this.IdentityTypeName.ToLower());
            }

            return spec.SatisfiedBy();
        }

        #endregion
    }
}
